home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 4.5 KB | 206 lines | [TEXT/MPS ] |
- /*
- File: ConfigurationDBStuff.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifdef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #ifndef __MAILGATEWAY__
- #include "MailGateway.h"
- #endif
-
- #ifndef __DEBUGASSERT__
- #include "DebugAssert.h"
- #endif
-
- #ifndef __TUPLEDATABASE__
- #include "TupleDatabase.h"
- #endif
-
- #ifndef __DEBUGCONSTANTS__
- #include "DebugConstants.h"
- #endif
-
- #ifndef __DEBUGSTREAM__
- #include "DebugStream.h"
- #endif
-
- extern TMailGateway* gMailGateway;
-
- extern void DumpHex ( ostream&, const void*, unsigned long );
-
- /***********************************|****************************************/
-
- #pragma segment ConfigDB
- void ShowConfigDB()
- {
- if (gMailGateway)
- {
- keith << "Configuration Info:" << endl;
- CTupleKey key;
- CDataItem data;
-
- for ( short itemNum = 1; gMailGateway->GetNthConfigKey(itemNum, key); ++itemNum )
- {
- if ( gMailGateway->GetConfigItem(key, data) )
- {
- keith << "key: " << key << " " << data << endl;
- }
- }
- }
- else
- SysBeep ( 10 );
- }
-
- /***********************************|****************************************/
-
- void ShowStatusDB()
- {
- keith << "Status Info: (Not Implemented)\n";
- }
-
- /***********************************|****************************************/
-
- Handle GetControlH(DialogPtr dialog, short index)
- {
- short itemType;
- Rect itemRect;
- Handle itemHandle;
-
- GetDItem(dialog, index, &itemType, &itemHandle, &itemRect);
-
- return itemHandle;
- }
-
- /***********************************|****************************************/
-
- enum ConfigDialogControls
- {
- kSetValue = 1,
- kDeleteTuple,
- kCancel,
- kAttributeKeyText,
- kAttributeValueText,
- kPascalType,
- kCType,
- kRStringType,
- kBooleanType,
- kLongType,
- kShortType,
- kRawData
- };
-
- void DoSetTupleDialog()
- {
- DialogPtr dialog;
- short tupleType = kPascalType;
- short itemHit;
-
- dialog = GetNewDialog(1000, nil, (WindowPtr) -1);
-
- ASSERT_RETURN ( dialog != nil );
-
- // Set the default tuple type
- SetCtlValue((ControlHandle) GetControlH(dialog, tupleType), 1);
-
- // Handle the dialog
- do {
- ModalDialog(nil, &itemHit);
-
- switch (itemHit)
- {
- case kPascalType:
- case kCType:
- case kRStringType:
- case kBooleanType:
- case kLongType:
- case kShortType:
- case kRawData:
- tupleType = itemHit;
- SetCtlValue((ControlHandle) GetControlH(dialog, itemHit), 1);
- for (int index = kPascalType; index <= kRawData; ++index)
- if (index != itemHit)
- SetCtlValue((ControlHandle) GetControlH(dialog, index), 0);
- break;
- }
- } while ((itemHit != kSetValue) && (itemHit != kDeleteTuple) && (itemHit != kCancel));
-
- Str255 string;
- GetIText ( GetControlH ( dialog, kAttributeKeyText ), string );
- CTupleKey attributeKey ( string );
- GetIText ( GetControlH ( dialog, kAttributeValueText ), string );
-
- if (itemHit == kSetValue)
- {
- switch (tupleType)
- {
- case kPascalType:
- gMailGateway->SetConfigItem ( attributeKey, CDataItem ( string, string [ 0 ] + 1 ) );
- break;
-
- case kCType:
- string [ string [ 0 ] + 1 ] = 0;
- gMailGateway->SetConfigItem ( attributeKey, CDataItem ( string + 1, string [ 0 ] + 1 ) );
- break;
-
- case kRStringType:
- {
- CDataItem buffer ( sizeof ( RString ) );
- OCEPToRString ( string, smRoman, (RString*) buffer.GetPhysicalStart (), (unsigned short) buffer.GetPhysicalLength () );
- gMailGateway->SetConfigItem ( attributeKey, buffer );
- break;
- }
-
- case kBooleanType:
- {
- Boolean value = IUEqualString ( string, "\ptrue" ) == 0;
- gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeBoolean ) );
- break;
- }
-
- case kLongType:
- {
- long value;
- StringToNum ( string, &value );
- gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeLongInteger ) );
- break;
- }
-
- case kShortType:
- {
- long tempValue;
- StringToNum ( string, &tempValue );
- short value = (short) tempValue;
- gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( &value, sizeof ( value ), typeShortInteger ) );
- break;
- }
-
- case kRawData:
- gMailGateway->SetConfigItem ( attributeKey, CWrapperDataItem ( string + 1, string [ 0 ], typeWildCard ) );
- break;
- }
- }
- else if (itemHit == kDeleteTuple)
- {
- gMailGateway->DeleteConfigItem(attributeKey);
- }
-
- DisposeDialog(dialog);
- }
-
- /***********************************|****************************************/
-